<?php 
namespace Home\Controller;
use Think\Controller;
	class RegController extends CommonController{
	   public function index(){
	   	//随机获取一条人类验证
	   		$res = D('verify')->getOneverify();
	   		$this->assign('res', $res);
	   		$this->display();
		}

		public function checkdate(){
			// var_dump(I('post.'));
			//验证密码是否一致
			$password = I('post.password');
			$repassword = I('post.repassword');
			$email = I('post.email');
			$nickname = I('post.nickname');
			if ($password!=$repassword) {
				$arr = array(
						'error' => 1,
						'info' =>'密码不一致重新输入'
					);
				echo json_encode($arr);
				exit();
			}
			//人类验证
				$verify = I('post.verify');
				 // var_dump($_SESSION['answer']);
			if ($_SESSION['answer']!=$verify) {
						$arr = array(
						'error' => 1,
						'info' =>'人类验证失败'
					);
				echo json_encode($arr);
				exit();
			}
			//验证邮箱
			if (D('user')->checkEmail($email)) {
						$arr = array(
						'error' => 1,
						'info' =>'邮箱已经存在重新输入'
					);
				echo json_encode($arr);
				exit();
			}

			if (D('user')->checkNickname($nickname)) {
						$arr = array(
						'error' => 1,
						'info' =>'昵称已存在重新输入'
					);
				echo json_encode($arr);
				exit();
			}

			$data = I('post.');
			$data['password'] = md5($password);
			$data['create_time'] = time();
			if (M('user')->add($data)) {
				$arr = array(
					'error' => 0,
					'info' => "注册成功"
					);
				echo json_encode($arr);
				exit();
			}else{
				$arr = array(
					'error' => 1,
					'info' => '注册失败'
					);
				echo json_encode($arr);
				exit();
			}

		}
	}














 ?>